home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 December / PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin / prgmming / win / vb1 / vbarray.exe / VBARRAY.FRM (.txt) < prev    next >
Visual Basic Form  |  1991-12-02  |  7KB  |  159 lines

  1. VBArray
  2. VB Array
  3. Form1
  4. ListBox
  5. IntDemo
  6. &Integer Array
  7. LngIntDemo
  8. &Long Integer Array
  9.     OtherDemo
  10. &Some Type Array
  11. OkCancel
  12. OkCancel
  13. &Quit
  14. Status
  15. Status
  16.     sTempFile
  17. hWndListBox
  18. nInitApp
  19. @    Form_Load
  20. nResult
  21. GetTempFileName9
  22. Status
  23. Caption
  24. OkCancel_Click
  25. Index
  26. IntDemo
  27. Value)
  28.     DoIntDemo
  29. VBARRAYU
  30. LngIntDemoF
  31. DoLngIntDemo
  32.     OtherDemo
  33. DoOtherDemo
  34. Form_Unloadh
  35. Cancel
  36.     tTempFile
  37. OFSTRUCT
  38. OpenFile
  39. OF_EXIST
  40. nRemoveTemp
  41.     OF_DELETE
  42. nBeforex
  43. nAfter
  44. nBytesM
  45. hFileOut
  46. hFileIn
  47. nIObytesB
  48. nFclose
  49. lMes8
  50.     OF_CREATEW
  51. OF_WRITE
  52. lwritey
  53. lclose
  54. OF_READe
  55. lread
  56. SendMessage
  57. LB_RESETCONTENT
  58. ListBox
  59. FALSE1
  60. lBefore
  61. lAfter
  62. tBefore
  63. SomeType
  64. tAfter
  65. nInteger
  66. sString
  67. lLong
  68. Before
  69. After
  70. Form_Paint
  71. GetFocus
  72. LB_SETTABSTOPS;
  73. fSize
  74. llseekD
  75. ptint
  76. OtherDemo_Click
  77. IntDemo_Click
  78. ListBox_Click
  79. FileSize
  80. LngIntDemo_Click
  81.     trailling
  82.     lFileSize
  83. OkCancel
  84.  VBARRAY *FAST* file I/O of arrays
  85.  Address questions/comments/improvements tom
  86.  Costas Kitsos, CIS ID: 73667,1755
  87.  Enjoy! 
  88.  holds a Windows supplied temp filename for the demo
  89.  listbox's hWnd so we can set tabs
  90.  Flag for Application Initialization
  91. Form_Load
  92.  Buffero
  93.  Ask Windows for a temp file. 
  94. Temp File: "
  95. OkCancel_Click
  96.  Do the Integer Array demo
  97. Integer Demo Failed"
  98.  Do the Long Integer Array demo
  99. Long Integer Demo Failed
  100.  Do the SomeType Array demo
  101. Some Type Demo Failed"
  102.  Quit pressedp
  103. Form_Unload
  104.  Used by OpenFilei
  105.  If our temp file exists, delete it.
  106. DoIntDemo
  107.  Declare variables
  108.  Used by OpenFile function
  109.  holds the Integers before I/O
  110.  holds the Integers after I/OO
  111.  Integerst
  112.  Use the Random number generator to fill nBefore() with 50 integers
  113.  ** I/O Starts here
  114.  Create our temp file and open it for writingo
  115.  If we have a file handle proceed 
  116.  calculate the number of bytes to be written (NumberOfElements * Size)
  117.  Since we want to write the entire array the formula would be:
  118.  nBytes = UBound(Array) * Len(Array(element)).  If we only neededS
  119.  twenty elements then nBytes = 20 * Len(Array(element)).  Since we're)
  120.  dealing with fixed length arrays, element can be any legitimate
  121.  array element.i
  122.  Write nBefore() to disk using API's lwrite function. 
  123.  We only need to pass the first array element.  The nBytes
  124.  parameter tells Windows how many bytes to write, or as far
  125.  as we're concerned how many array elements.
  126.  Get the file size with llseek.  By specifying 0 for lOffset and
  127.  and 2 for iOrigin we're saying seek position 0 from the end ofh
  128.  the file.  In other words, give us the FileSize.r
  129.  close the output file. 
  130.  Now let's see if it worked.  Open the file for reading.
  131.  We'll use the nAfter() array this time, nBytes is the same.
  132.  close the input file.
  133.  Let's prove that it worked.  First, clear the list box.
  134.  Add a title.
  135. Before
  136. After"
  137.  Add the nBefore() and nAfter() contents to the listbox.
  138. Temp File: "
  139.  bytes
  140.  success
  141.  failure
  142. DoLngIntDemo
  143.  Please see the DoIntDemo function for comments
  144. Before
  145. After"
  146. Temp File: "
  147.  bytes
  148. DoOtherDemo
  149.  Please see the DoIntDemo function for comments
  150. abcde"
  151. Before
  152. After"
  153. Temp File: "
  154.  bytes
  155. Form_Paint
  156.  get the listbox's hWnd
  157.  Set 1 tab stop at position 105n
  158. set the flag to FALSE so we don't repeat this
  159.